Skip to content

Lazy-evaluate ENSDb modules in ENSApi#2174

Merged
tk-o merged 10 commits into
mainfrom
feat/2029-di-for-ensdb-modules
May 22, 2026
Merged

Lazy-evaluate ENSDb modules in ENSApi#2174
tk-o merged 10 commits into
mainfrom
feat/2029-di-for-ensdb-modules

Conversation

@tk-o
Copy link
Copy Markdown
Member

@tk-o tk-o commented May 21, 2026

Lite PR

Tip: Review docs on the ENSNode PR process

Summary

  • Replaces all eagerly-evaluated imports from @/lib/ensdb/singleton with the lazily-evaluated counterparts from @/di.

Why

  • We want to phase out the use of lazy/lazyProxy primitives from ENSNode codebase.

Testing

  • Ran static code checks, testing suite and ENSApi locally while testing it in the local ENSAdmin UI.

Notes for Reviewer (Optional)

  • This is a follow up PR to DI container for ENSApi #2159
  • Review commit-by-commit (one commit updates the ENSDb modules creation, the other covers mechanical updates).

Pre-Review Checklist (Blocking)

  • This PR does not introduce significant changes and is low-risk to review quickly.
  • Relevant changesets are included (or are not required)

@tk-o tk-o requested a review from a team as a code owner May 21, 2026 19:43
Copilot AI review requested due to automatic review settings May 21, 2026 19:43
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 21, 2026

🦋 Changeset detected

Latest commit: a1ad07c

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 22 packages
Name Type
@ensnode/ensdb-sdk Minor
ensapi Minor
ensindexer Minor
@ensnode/integration-test-env Minor
ensadmin Minor
ensrainbow Minor
fallback-ensapi Minor
enssdk Minor
enscli Minor
enskit Minor
ensskills Minor
@ensnode/datasources Minor
@ensnode/ensrainbow-sdk Minor
@ensnode/ensnode-sdk Minor
@ensnode/ponder-sdk Minor
@ensnode/ponder-subgraph Minor
@ensnode/shared-configs Minor
@docs/ensnode Minor
@docs/ensrainbow Minor
@namehash/ens-referrals Minor
@namehash/namehash-ui Minor
@ensnode/ensindexer-perf-testing Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link
Copy Markdown
Contributor

vercel Bot commented May 21, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
admin.ensnode.io Ready Ready Preview, Comment May 22, 2026 11:50am
enskit-react-example.ensnode.io Ready Ready Preview, Comment May 22, 2026 11:50am
ensnode.io Ready Ready Preview, Comment May 22, 2026 11:50am
1 Skipped Deployment
Project Deployment Actions Updated (UTC)
ensrainbow.io Skipped Skipped May 22, 2026 11:50am

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 21, 2026

Review Change Stack

Warning

Rate limit exceeded

@tk-o has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 56 minutes and 39 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 100c80e2-74c4-4b6f-ab22-91c4efcb68e6

📥 Commits

Reviewing files that changed from the base of the PR and between 5b5366b and a1ad07c.

📒 Files selected for processing (6)
  • .changeset/brown-spies-press.md
  • apps/ensapi/src/config/config.singleton.test.ts
  • apps/ensapi/src/di.ts
  • apps/ensapi/src/index.ts
  • packages/ensdb-sdk/src/client/ensdb-reader.test.ts
  • packages/ensdb-sdk/src/client/ensdb-reader.ts
📝 Walkthrough

Walkthrough

Removes the ENS DB singleton and updates the DI container to instantiate ENSDbReader from environment; all ENS DB/schema/client consumers are changed to read those dependencies from di.context at runtime, including caches, probes, library functions, GraphQL resolvers, and tests.

Changes

Singleton Dependency Injection Refactor

Layer / File(s) Summary
DI infrastructure & ENS DB wiring
apps/ensapi/src/config/ensdb-config.ts, apps/ensapi/src/di.ts
buildEnsDbConfigFromEnvironment uses EnsDbEnvironment; di computes ensDbConfig from EnsApiEnvironment and constructs EnsDbReader for ensDbClient; di.init() is now async and performs awaited health/cache/RPC checks.
Test adjustments for DI
apps/ensapi/src/config/config.schema.test.ts, apps/ensapi/src/config/config.singleton.test.ts
Tests now use di.init()/di.destroy() and exercise DI-based init/failure behavior; logger mock includes makeLogger.
Cache loaders
apps/ensapi/src/cache/indexing-status.cache.ts, apps/ensapi/src/cache/stack-info.cache.ts
Cache loader functions dynamically import @/di and read ensDbClient from di.context at runtime to avoid import-time DB initialization.
Probe handlers
apps/ensapi/src/handlers/ensapi-probes/ensapi-probes-api.ts
Health/readiness handlers obtain ensDbClient from di.context within the route handlers before checks.
Library DB access (analytics, name-tokens, protocol-accel, registrar-actions)
apps/ensapi/src/lib/*
Functions and queries in analytics, name-tokens, protocol-acceleration, and registrar-actions now destructure ensDb/ensIndexerSchema from di.context at query time.
Omnigraph helpers & find resolvers
apps/ensapi/src/omnigraph-api/lib/*, apps/ensapi/src/omnigraph-api/context.ts
Per-request loaders and helper functions source DB/schema from di.context for batch loading, ordering, filtering, and query construction.
Find-domains & find-events resolvers
apps/ensapi/src/omnigraph-api/lib/find-domains/*, apps/ensapi/src/omnigraph-api/lib/find-events/*
Resolver code now builds filters, counts, and paginated queries using ensDb/ensIndexerSchema from di.context.
GraphQL schema types & resolvers
apps/ensapi/src/omnigraph-api/schema/*
builder.objectRef generics reference di.context.ensIndexerSchema.$inferSelect; loaders and connection resolvers read ensDb/ensIndexerSchema from di.context before queries.
Root connection resolvers
apps/ensapi/src/omnigraph-api/schema/query.ts
allDomains, resolvers, and registrations resolvers now destructure ensDb and ensIndexerSchema from di.context inside resolve functions before returning lazyConnection results.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related issues

  • #2029: The issue describes the DI refactor plan that removes module-level ENS DB singletons and moves consumers to di.context, matching this PR.

Possibly related PRs

  • namehash/ensnode#2155: Overlaps on find-domains resolver helper changes (cursor/order logic using di.context).
  • namehash/ensnode#2159: Also migrates cache and runtime wiring to use the ENSApi DI container and di.context for DB access.
  • namehash/ensnode#1809: Related edits to indexing-status cache; this PR changes how ensDbClient is obtained while that PR adjusts the snapshot call.

Poem

🐰 I hopped through code and found a fuss,

"No singletons," I said with a cuss—
DI now wakes when modules call,
Context serves the DB for all,
Hooray, clean starts for one and us!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: moving from eager singleton imports to lazy DI-based evaluation of ENSDb modules.
Description check ✅ Passed The description follows the template structure with Summary, Why, Testing, Notes, and Pre-Review Checklist sections all completed with relevant details.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/2029-di-for-ensdb-modules

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 21, 2026

Greptile Summary

This PR completes the migration away from lazyProxy singletons by replacing all imports from @/lib/ensdb/singleton with direct di.context access across ~38 files, and deleting the now-unused singleton.ts module.

  • di.init() is promoted to async, eagerly verifying ENSDb connectivity (via isHealthy()), populating caches, and probing the ENS Root Chain RPC before the application begins serving traffic.
  • EnsDbReader.destroy() is added to properly close the underlying pg.Pool, and di.destroy() is updated to async so it awaits this teardown during graceful shutdown.
  • All call sites that previously imported ensDb/ensIndexerSchema from the singleton now destructure them from di.context at the top of the relevant function body, keeping the lazy-evaluation semantics without the lazyProxy primitive.

Confidence Score: 5/5

Safe to merge — this is a mechanical refactoring with no changes to business logic or data paths.

All 38 files follow the same consistent migration pattern. The new async init() correctly sequences ENSDb health verification, cache population, and RPC probing. Previously flagged issues (isHealthy return value not checked, missing MockEnsDbReader.destroy(), unawaited di.init() in tests) are resolved in this PR.

No files require special attention. The @ts-expect-error in packages/ensdb-sdk/src/client/ensdb-reader.ts for $client.end() is documented and covered by new tests.

Important Files Changed

Filename Overview
apps/ensapi/src/di.ts init() is now async and eagerly verifies ENSDb health, caches, and RPC; destroy() properly awaits connection pool teardown. Control flow and error wrapping are correct.
apps/ensapi/src/index.ts init() is intentionally fired non-blocking (void + .catch → process.exit); destroy() is properly awaited during graceful shutdown.
packages/ensdb-sdk/src/client/ensdb-reader.ts New destroy() method uses @ts-expect-error to call $client.end() — an undocumented but real Drizzle node-postgres API; well-documented and covered by new tests.
packages/ensdb-sdk/src/client/ensdb-reader.test.ts New destroy() tests cover the happy path and error propagation; endMock properly plumbed into drizzleClientMock.$client.
apps/ensapi/src/config/config.singleton.test.ts Tests rewritten to use di.init()/di.destroy(); MockEnsDbReader now includes async destroy(). All di.init() calls are properly awaited in both success and error paths.
apps/ensapi/src/lib/ensdb/singleton.ts File deleted; all consumers migrated to di.context — no remaining references.
apps/ensapi/src/config/ensdb-config.ts Default lazyProxy export removed; buildEnsDbConfigFromEnvironment now takes EnsDbEnvironment instead of NodeJS.ProcessEnv for tighter typing.
apps/ensapi/src/cache/indexing-status.cache.ts Async import of di moved to the top of the SWR fn callback; circular dependency avoided correctly.
apps/ensapi/src/cache/stack-info.cache.ts Async di import moved to top of fn callback alongside ensDbClient; di.context.ensApiConfig access for buildEnsNodeStackInfo is unchanged and correct.
apps/ensapi/src/omnigraph-api/lib/find-domains/find-domains-resolver.ts di.context destructuring at multiple call sites; type-level typeof di.context.ensIndexerSchema usage is compile-time only and equivalent to the prior singleton type.

Reviews (6): Last reviewed commit: "Merge remote-tracking branch 'origin/mai..." | Re-trigger Greptile

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR migrates ENSApi’s ENSDb access away from the @/lib/ensdb/singleton lazyProxy-based singleton and onto the @/di container so ENSDb modules are instantiated lazily via DI getters instead of import-time evaluation.

Changes:

  • Replace ensDb / ensIndexerSchema / ensDbClient imports from @/lib/ensdb/singleton with di.context.* across Omnigraph schema + supporting libs/handlers.
  • Move ENSDb config + client construction into apps/ensapi/src/di.ts (build config from env on-demand; instantiate EnsDbReader on first access).
  • Remove apps/ensapi/src/lib/ensdb/singleton.ts and update tests/caches to reference DI.

Reviewed changes

Copilot reviewed 34 out of 34 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
apps/ensapi/src/omnigraph-api/schema/resolver.ts Swap ENSDb/schema access to di.context inside resolver loaders/field resolvers.
apps/ensapi/src/omnigraph-api/schema/resolver-records.ts Use di.context.ensDb for ResolverRecords loader.
apps/ensapi/src/omnigraph-api/schema/resolver-permissions-user.ts Update PermissionsUser typing to reference DI-provided schema types.
apps/ensapi/src/omnigraph-api/schema/renewal.ts Use di.context.ensDb for Renewal loader.
apps/ensapi/src/omnigraph-api/schema/registry.ts Use DI for registry loading + subregistry-domain connection queries.
apps/ensapi/src/omnigraph-api/schema/registry-permissions-user.ts Update PermissionsUser typing to reference DI-provided schema types.
apps/ensapi/src/omnigraph-api/schema/registration.ts Use DI for registration loading + renewals queries.
apps/ensapi/src/omnigraph-api/schema/query.ts Use DI for “dev method” connections (allDomains/resolvers/registrations).
apps/ensapi/src/omnigraph-api/schema/permissions.ts Use DI for Permissions/Resource/User loaders + event connections.
apps/ensapi/src/omnigraph-api/schema/label.ts Update Label typing to reference DI-provided schema types.
apps/ensapi/src/omnigraph-api/schema/event.ts Use di.context.ensDb for Event loader.
apps/ensapi/src/omnigraph-api/schema/domain.ts Use DI for domain loading + registrations/events/permissions queries.
apps/ensapi/src/omnigraph-api/schema/account.ts Use DI for account loading + permissions queries.
apps/ensapi/src/omnigraph-api/lib/get-latest-registration.ts Read ENSDb via DI inside helper.
apps/ensapi/src/omnigraph-api/lib/get-domain-resolver.ts Read ENSDb via DI inside helper.
apps/ensapi/src/omnigraph-api/lib/get-domain-by-interpreted-name.ts Read ENSDb/schema via DI before executing recursive SQL.
apps/ensapi/src/omnigraph-api/lib/find-events/find-events-resolver.ts Replace ENSDb/schema singleton usage with DI throughout event query builder.
apps/ensapi/src/omnigraph-api/lib/find-domains/find-domains-resolver.ts Replace ENSDb/schema singleton usage with DI throughout domain query builder.
apps/ensapi/src/omnigraph-api/lib/find-domains/find-domains-resolver-helpers.ts Replace schema singleton usage with DI in ordering/cursor helpers.
apps/ensapi/src/omnigraph-api/context.ts Use DI for DataLoader query against ENSDb/schema.
apps/ensapi/src/lib/registrar-actions/find-registrar-actions.ts Replace ENSDb/schema singleton usage with DI throughout query building.
apps/ensapi/src/lib/protocol-acceleration/get-records-from-index.ts Replace ENSDb singleton usage with DI.
apps/ensapi/src/lib/protocol-acceleration/get-primary-name-from-index.ts Replace ENSDb singleton usage with DI.
apps/ensapi/src/lib/protocol-acceleration/find-resolver.ts Replace ENSDb singleton usage with DI in index-backed resolver lookup.
apps/ensapi/src/lib/name-tokens/find-name-tokens-for-domain.ts Replace ENSDb/schema singleton usage with DI in typed select + query.
apps/ensapi/src/lib/ensdb/singleton.ts Remove ENSApi ENSDb singleton module.
apps/ensapi/src/lib/ensanalytics/referrer-leaderboard/database.ts Replace ENSDb/schema singleton usage with DI for referral queries.
apps/ensapi/src/handlers/ensapi-probes/ensapi-probes-api.ts Use di.context.ensDbClient for health/readiness probes.
apps/ensapi/src/di.ts Move ENSDb config + EnsDbReader instantiation into DI context getters.
apps/ensapi/src/config/ensdb-config.ts Tighten env typing for ENSDb config builder to EnsDbEnvironment.
apps/ensapi/src/config/config.singleton.test.ts Update singleton bootstrap tests to initialize/use DI container.
apps/ensapi/src/config/config.schema.test.ts Remove ENSDb singleton mocks; adjust imports accordingly.
apps/ensapi/src/cache/stack-info.cache.ts Switch to dynamic DI import + di.context.ensDbClient for metadata reads.
apps/ensapi/src/cache/indexing-status.cache.ts Switch to dynamic DI import + di.context.ensDbClient for metadata reads.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread apps/ensapi/src/omnigraph-api/schema/label.ts
Comment thread apps/ensapi/src/omnigraph-api/schema/registry-permissions-user.ts
Comment thread apps/ensapi/src/omnigraph-api/schema/resolver-permissions-user.ts
Comment thread apps/ensapi/src/di.ts
@tk-o tk-o force-pushed the feat/2029-di-for-ensdb-modules branch from d943075 to 3fa3adb Compare May 21, 2026 19:49
@vercel vercel Bot temporarily deployed to Preview – ensrainbow.io May 21, 2026 19:49 Inactive
@vercel vercel Bot temporarily deployed to Preview – ensnode.io May 21, 2026 19:49 Inactive
@vercel vercel Bot temporarily deployed to Preview – admin.ensnode.io May 21, 2026 19:49 Inactive
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@apps/ensapi/src/cache/indexing-status.cache.ts`:
- Around line 32-37: The dynamic import of "`@/di`" and the subsequent access to
di.context/ensDbClient occur before the existing try block so any failures skip
the loader’s structured error logging; move the import("`@/di`") and the const {
ensDbClient } = di.context into the existing try block (or wrap them in their
own try/catch that forwards errors to the same loader error handler) so import
rejections and missing context errors are caught and logged by the loader’s
structured error path, ensuring the same error handling used elsewhere in this
module.

In `@apps/ensapi/src/cache/stack-info.cache.ts`:
- Around line 43-48: Move the dynamic DI import and context access into the
existing try block so any failures are caught and routed through the function's
error logging; specifically, relocate the await import("`@/di`").then((mod) =>
mod.default) and the subsequent const { ensDbClient } = di.context into the try
that wraps the cache load logic (the block that currently catches and logs load
errors) so that errors resolving di or accessing ensDbClient are logged like
other load failures.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 01efee16-ee34-4955-be6a-7db3525f8067

📥 Commits

Reviewing files that changed from the base of the PR and between 335f072 and d943075.

📒 Files selected for processing (34)
  • apps/ensapi/src/cache/indexing-status.cache.ts
  • apps/ensapi/src/cache/stack-info.cache.ts
  • apps/ensapi/src/config/config.schema.test.ts
  • apps/ensapi/src/config/config.singleton.test.ts
  • apps/ensapi/src/config/ensdb-config.ts
  • apps/ensapi/src/di.ts
  • apps/ensapi/src/handlers/ensapi-probes/ensapi-probes-api.ts
  • apps/ensapi/src/lib/ensanalytics/referrer-leaderboard/database.ts
  • apps/ensapi/src/lib/ensdb/singleton.ts
  • apps/ensapi/src/lib/name-tokens/find-name-tokens-for-domain.ts
  • apps/ensapi/src/lib/protocol-acceleration/find-resolver.ts
  • apps/ensapi/src/lib/protocol-acceleration/get-primary-name-from-index.ts
  • apps/ensapi/src/lib/protocol-acceleration/get-records-from-index.ts
  • apps/ensapi/src/lib/registrar-actions/find-registrar-actions.ts
  • apps/ensapi/src/omnigraph-api/context.ts
  • apps/ensapi/src/omnigraph-api/lib/find-domains/find-domains-resolver-helpers.ts
  • apps/ensapi/src/omnigraph-api/lib/find-domains/find-domains-resolver.ts
  • apps/ensapi/src/omnigraph-api/lib/find-events/find-events-resolver.ts
  • apps/ensapi/src/omnigraph-api/lib/get-domain-by-interpreted-name.ts
  • apps/ensapi/src/omnigraph-api/lib/get-domain-resolver.ts
  • apps/ensapi/src/omnigraph-api/lib/get-latest-registration.ts
  • apps/ensapi/src/omnigraph-api/schema/account.ts
  • apps/ensapi/src/omnigraph-api/schema/domain.ts
  • apps/ensapi/src/omnigraph-api/schema/event.ts
  • apps/ensapi/src/omnigraph-api/schema/label.ts
  • apps/ensapi/src/omnigraph-api/schema/permissions.ts
  • apps/ensapi/src/omnigraph-api/schema/query.ts
  • apps/ensapi/src/omnigraph-api/schema/registration.ts
  • apps/ensapi/src/omnigraph-api/schema/registry-permissions-user.ts
  • apps/ensapi/src/omnigraph-api/schema/registry.ts
  • apps/ensapi/src/omnigraph-api/schema/renewal.ts
  • apps/ensapi/src/omnigraph-api/schema/resolver-permissions-user.ts
  • apps/ensapi/src/omnigraph-api/schema/resolver-records.ts
  • apps/ensapi/src/omnigraph-api/schema/resolver.ts
💤 Files with no reviewable changes (1)
  • apps/ensapi/src/lib/ensdb/singleton.ts

Comment thread apps/ensapi/src/cache/indexing-status.cache.ts
Comment thread apps/ensapi/src/cache/stack-info.cache.ts
Copilot AI review requested due to automatic review settings May 22, 2026 10:47
@vercel vercel Bot temporarily deployed to Preview – ensnode.io May 22, 2026 10:47 Inactive
@vercel vercel Bot temporarily deployed to Preview – admin.ensnode.io May 22, 2026 10:47 Inactive
@vercel vercel Bot temporarily deployed to Preview – ensrainbow.io May 22, 2026 10:47 Inactive
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 34 out of 34 changed files in this pull request and generated 7 comments.

Comments suppressed due to low confidence (1)

apps/ensapi/src/config/config.singleton.test.ts:37

  • These tests call di.init() without await, but init() is now async. This will cause unhandled Promise rejections and race with afterEach(di.destroy()). Also, di.init() now performs ENSDb/RPC connectivity checks; without stubbing/mocking those, the suite will try to hit real services and become flaky. Await di.init() and mock the health checks (or test context construction without running init()).
  it("constructs EnsDbReader from real env wiring without errors", async () => {
    di.init();
    const { ensDbClient, ensDb, ensIndexerSchema } = di.context;
    expect(ensDbClient.ensIndexerSchemaName).toBe(VALID_ENSINDEXER_SCHEMA_NAME);
    expect(ensDb).toBeDefined();
    expect(ensIndexerSchema).toBeDefined();
  }, 10_000);

Comment thread apps/ensapi/src/di.ts
Comment thread apps/ensapi/src/di.ts
Comment thread apps/ensapi/src/di.ts
Comment thread apps/ensapi/src/cache/stack-info.cache.ts
Comment thread apps/ensapi/src/cache/indexing-status.cache.ts
Comment thread apps/ensapi/src/config/config.singleton.test.ts
Comment thread apps/ensapi/src/config/config.singleton.test.ts
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@apps/ensapi/src/config/config.singleton.test.ts`:
- Around line 32-33: The test calls di.init() without awaiting it and then
accesses di.context, which can leak unhandled rejections; update the tests to
await the returned promise from di.init() (e.g., await di.init()) and for the
ENSDB_URL/ENSINDEXER_SCHEMA_NAME negative cases assert that await di.init()
rejects (using your test runner's reject assertion) instead of accessing
di.context. Ensure all tests that rely on di.context run only after awaiting
di.init(), and replace direct di.context.ensDbClient access in failure scenarios
with assertions on the rejected promise from di.init().

In `@apps/ensapi/src/di.ts`:
- Around line 258-270: The DI init path leaves this._context populated if
connectivity/cache/RPC checks fail; update the init() flow (after calling
loadContext()) to clear this._context on any caught error to avoid a
half-initialized container: in each catch block that wraps ENSDb/RPC/cache/other
checks, set this._context = undefined (or call a single
unloadContext/clearContext helper) before re-throwing so retries start from a
clean state; apply the same fix to the similar catch blocks referenced (lines
around 272-286 and 290-299) and centralize the cleanup where possible.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 451e5d54-43d1-49ce-907d-76637cf91475

📥 Commits

Reviewing files that changed from the base of the PR and between d943075 and 5b5366b.

📒 Files selected for processing (34)
  • apps/ensapi/src/cache/indexing-status.cache.ts
  • apps/ensapi/src/cache/stack-info.cache.ts
  • apps/ensapi/src/config/config.schema.test.ts
  • apps/ensapi/src/config/config.singleton.test.ts
  • apps/ensapi/src/config/ensdb-config.ts
  • apps/ensapi/src/di.ts
  • apps/ensapi/src/handlers/ensapi-probes/ensapi-probes-api.ts
  • apps/ensapi/src/lib/ensanalytics/referrer-leaderboard/database.ts
  • apps/ensapi/src/lib/ensdb/singleton.ts
  • apps/ensapi/src/lib/name-tokens/find-name-tokens-for-domain.ts
  • apps/ensapi/src/lib/protocol-acceleration/find-resolver.ts
  • apps/ensapi/src/lib/protocol-acceleration/get-primary-name-from-index.ts
  • apps/ensapi/src/lib/protocol-acceleration/get-records-from-index.ts
  • apps/ensapi/src/lib/registrar-actions/find-registrar-actions.ts
  • apps/ensapi/src/omnigraph-api/context.ts
  • apps/ensapi/src/omnigraph-api/lib/find-domains/find-domains-resolver-helpers.ts
  • apps/ensapi/src/omnigraph-api/lib/find-domains/find-domains-resolver.ts
  • apps/ensapi/src/omnigraph-api/lib/find-events/find-events-resolver.ts
  • apps/ensapi/src/omnigraph-api/lib/get-domain-by-interpreted-name.ts
  • apps/ensapi/src/omnigraph-api/lib/get-domain-resolver.ts
  • apps/ensapi/src/omnigraph-api/lib/get-latest-registration.ts
  • apps/ensapi/src/omnigraph-api/schema/account.ts
  • apps/ensapi/src/omnigraph-api/schema/domain.ts
  • apps/ensapi/src/omnigraph-api/schema/event.ts
  • apps/ensapi/src/omnigraph-api/schema/label.ts
  • apps/ensapi/src/omnigraph-api/schema/permissions.ts
  • apps/ensapi/src/omnigraph-api/schema/query.ts
  • apps/ensapi/src/omnigraph-api/schema/registration.ts
  • apps/ensapi/src/omnigraph-api/schema/registry-permissions-user.ts
  • apps/ensapi/src/omnigraph-api/schema/registry.ts
  • apps/ensapi/src/omnigraph-api/schema/renewal.ts
  • apps/ensapi/src/omnigraph-api/schema/resolver-permissions-user.ts
  • apps/ensapi/src/omnigraph-api/schema/resolver-records.ts
  • apps/ensapi/src/omnigraph-api/schema/resolver.ts
💤 Files with no reviewable changes (1)
  • apps/ensapi/src/lib/ensdb/singleton.ts

Comment thread apps/ensapi/src/config/config.singleton.test.ts Outdated
Comment thread apps/ensapi/src/di.ts
@vercel vercel Bot temporarily deployed to Preview – ensrainbow.io May 22, 2026 11:03 Inactive
@vercel vercel Bot temporarily deployed to Preview – admin.ensnode.io May 22, 2026 11:03 Inactive
tk-o added 2 commits May 22, 2026 13:34
… allows cleaning up database connection resources when the connection is no longer needed.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 37 out of 37 changed files in this pull request and generated 6 comments.

Comment thread apps/ensapi/src/di.ts
Comment thread apps/ensapi/src/di.ts
Comment thread apps/ensapi/src/index.ts
Comment thread apps/ensapi/src/config/config.singleton.test.ts
Comment thread packages/ensdb-sdk/src/client/ensdb-reader.ts
Comment thread packages/ensdb-sdk/src/client/ensdb-reader.ts
Comment thread apps/ensapi/src/di.ts
Comment thread apps/ensapi/src/config/config.singleton.test.ts
@vercel vercel Bot temporarily deployed to Preview – admin.ensnode.io May 22, 2026 11:48 Inactive
@vercel vercel Bot temporarily deployed to Preview – ensrainbow.io May 22, 2026 11:48 Inactive
@vercel vercel Bot temporarily deployed to Preview – ensnode.io May 22, 2026 11:48 Inactive
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 38 out of 38 changed files in this pull request and generated 2 comments.

Comment thread apps/ensapi/src/di.ts
Comment thread packages/ensdb-sdk/src/client/ensdb-reader.ts
@tk-o tk-o merged commit bb0b244 into main May 22, 2026
20 checks passed
@tk-o tk-o deleted the feat/2029-di-for-ensdb-modules branch May 22, 2026 12:19
@github-actions github-actions Bot mentioned this pull request May 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants